using Gameplay.PVE.Entity;
using UnityEngine;

namespace Gameplay.PVE
{
    public class ObstacleHudComponent : HudComponent
    {
        private float lastHitTime;
        public override void Initialize(UnitBase unit)
        {
            base.Initialize(unit);
            bloodBarTrans.gameObject.SetActive(false);
            bloodBarTrans = uiObject.transform.Find("bloodBar/barHpBg");
            bloodBarTrans.gameObject.SetActive(true);
        }

        protected override void InitPosition()
        {
            
        }

        protected override void UpdateHp()
        {
            //bloodText.text = unit.Data.CurrentHp.ToString();
            float percent = (float) unit.Data.CurrentHp / unit.Data.TotalHp;
            if (percent < 1)
            {
                bloodBar.SetActive(true);
                uiObject.transform.position = unit.Data.position + new Vector3(0, 1.8f, 0);
            }

            if (percent < 0)
            {
                percent = 0;
            }

            realPercent = percent;
            //bloodBarTrans.localScale = new Vector3(percent,1,1);
            lastHitTime = TimeManager.logicTime;
        }

        public override void Update()
        {
            if (unit.Data.isDead)
            {
                return;
            }

            UpdateHpTransition();
            if (TimeManager.logicTime - lastHitTime > 2)
            {
                bloodBar.SetActive(false);
            }
            uiObject.transform.forward = cameraTrans.forward;
        }
    }
}